/**
 * 工商申请
 * @author   Liu Yutao <koal@vip.qq.com>
 * @date     2018/3/15 10:24
 */

/**
 * 证件类型隐藏学历、电话、电子邮箱
 * 相应cardType的change事件
 * @param event
 */
function memberCardTypeSwitch(event) {
    var currentForm = $(event.target).parents("form");
    currentForm.find("select[name=cardType]").on('change', function () {
        memberCardTypeSwitchExecute(this, currentForm);
    });
}

/**
 * 证件类型实际执行方法
 */
function memberCardTypeSwitchExecute(thiz, currentForm) {
    if ($(thiz).val() != 1) {
        currentForm.find(".education-box").hide().find("input").attr("disabled", true);
        currentForm.find(".phone-box").hide().find("input").attr("disabled", true);
        currentForm.find(".email-box").hide().find("input").attr("disabled", true);
        window.openType = 2;
    } else {
        currentForm.find(".education-box").show().find("input").removeAttr("disabled");
        currentForm.find(".phone-box").show().find("input").removeAttr("disabled");
        currentForm.find(".email-box").show().find("input").removeAttr("disabled");
        window.openType = 1;
    }

}

/**
 * 高拍仪读取身份证信息
 * @param formId
 * @returns
 */

function readIDcard(formId){
    var obj = ReadIDCard();
	$("#shareholder_"+formId).find("input[name='name']").val(obj.name);
	$("#shareholder_"+formId).find("select[name='cardType']").val(1);
	$("#shareholder_"+formId).find("input[name='cardNumber']").val(obj.idcard);
    
		var result = updateBase64('data:image/jpeg;base64,' + obj.IDcard_frontImg_base64);
		if (result.status) {
			$("#shareholder_"+formId).find("input[name='cardFrontPicture']").val(result.url);
			$("#shareholder_"+formId+" .cardFrontPictureShow").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><a href=\"" + result.domain + result.url + "\" target=\"_blank\"><img src=\"" + result.domain + result.url + "\"  style=\"width: 100%\"></a></div></div>");
		} else {
			obj.message=result.message;
		}	

		
	var result = updateBase64('data:image/jpeg;base64,' + obj.IDcard_backImg_base64);
	if (result.status) {
		$("#shareholder_"+formId).find("input[name='cardBackPicture']").val(result.url);
		$("#shareholder_"+formId+" .cardBackPictureShow").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><a href=\"" + result.domain + result.url + "\" target=\"_blank\"><img src=\"" + result.domain + result.url + "\"   style=\"width: 100%\"></a></div></div>");
	} else {
		obj.message=result.message;
	}	
    
}

define([
    'jquery',
    'baseUtils',
    'base',
    'msgTool',
    'plugins/bootstrap-dialog/bootstrap-dialog',
    'css!global/plugins/fileInput/fileinput.min.css',
    'plugins/fileInput/fileinput.min',
	'common/pc_camera'
], function ($, baseUtils, base, msgTool,BootstrapDialog) {
    base();


    /**
     * form表单转换成json
     */
    function getFormJson(form) {
        var data = {};
        var a = $(form).serializeArray();
        $.each(a, function () {
            if (data[this.name] !== undefined) {
                if (!data[this.name].push) {
                    data[this.name] = [data[this.name]];
                }
                data[this.name].push(this.value || '');
            } else {
                data[this.name] = this.value || '';
            }
        });
        return data;
    }


    /**
     * 证件照上传
     * @param rootName      上传css的根节点名字
     * @param cssName       上传css名字
     * @param single        是否单个，true单个，false多个
     * @param filesType     文件类型1文件，0图片
     * @param showCaption   是否显示input框，false隐藏，true显示
     * @param uploadText    按钮文件
     * @param errorCssName  错误css名字
     * @param valName       设置值的节点名字
     * @param showName      展示图的节点名字
     */
    function uploader(rootName, cssName, single, filesType, showCaption, uploadText, errorCssName, valName, showName) {
        //节点判断
        var valNode, showNode, errorNode;
            //赋值节点
            valNode = $(valName);
            //展示节点
            showNode = $(showName);
            //错误节点
            errorNode = $(errorCssName);

        //上传
        return $.baseUtils.uploader({
            filesType: filesType,
            showCaption: showCaption,
            browseLabel: "选择" + uploadText,
            uploadLabel: "上传",
            rootName: rootName,
            cssName: cssName,
            errorCssName: errorCssName === null ? "#error-message" : errorCssName
        }).on("fileuploaded", function (event, data) {
            if (data.response !== null && data.response.status) {
                if (single) {
                    valNode.val(data.response.url);
                    showNode.html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><a href=\"" + data.response.domain + data.response.url + "\" target=\"_blank\"><img src=\"" + data.response.domain + data.response.url + "\"></a></div> <div class=\"caption\"><div class=\"btn btn-block btn-danger deletetCover\" onclick=\"$(this).parent().parent().remove()\"><i class=\"iconfont icon-remove\"></i>&nbsp;删除</div></div> </div>");
                } else {
                    showNode.append("<div class=\"col-xs-12 col-sm-4 mb15\"><div class=\"thumbnail images-box\"><input type=\"hidden\" name=\"companyImagesList\" value=\"" + data.response.url + "\"><a href=\"" + data.response.domain + data.response.url + "\" target=\"_blank\"><img src=\"" + data.response.domain + data.response.url + "\"></a></div><div class=\"caption\"><div class=\"btn btn-block btn-danger deletetCover\" onclick=\"$(this).parent().parent().remove()\"><i class=\"iconfont icon-remove\"></i>&nbsp;删除</div></div></div>");
                }
            } else {
                $(errorNode === null ? "#error-message" : errorNode).text(data.response.message);
            }
        });
    }


    //执行
    return {
        /**
         * 基础
         */
        index: function () {

            if (window.isAIO !== undefined && window.isAIO) {
                //删除pc版上传代码
                $("#imagesUploader").remove();
                $("#error-message").remove();
                //添加一体机摄像头代码
                $("#camera_tool_open").html("<label for=\"cardFrontUploader\" class=\"control-label\">请打开高拍仪后，拍摄《租赁合同或房产证》照片，点击确认图片添加资料，可上传多张。</label>" +
                    "<div class=\"col-md-8 alert alert-warning  btn-group btn-group-justified\">" +
                    "<button type='button' class=\"btn btn-default btn-lg open_camera\" data-open-type=\"1\"><i class=\"iconfont icon-paishe\" style=\"font-size:2rem\"></i>&nbsp;打开高拍仪</button>\n" +
                    "<button type='button' class=\"btn btn-default btn-lg confirm_photo\" data-open-type=\"1\"><i class=\"iconfont icon-paishe\" style=\"font-size:2rem\"></i>&nbsp;确认图片</button>\n" +
                    "<button type='button' class=\"btn btn-default btn-lg btn-block close_camera\"><i class=\"iconfont icon-guanbi\" style=\"font-size:2rem\"></i>&nbsp;关闭高拍仪</button>\n" +
                    "</div>");
            } else {
                //上传执照
                uploader(null, "#imagesUploader", false, 0, true, "证照资料", null, null, "#imagesUploadShow");
                if (checkDevice()) {
                    //添加pc高拍仪代码
	                $("#camera_tool_open").html(
	                    "<div class=\"col-md-8 alert alert-warning  btn-group btn-group-justified\">" +
	                    "<a href=\"#\" class=\"btn btn-default btn-lg \"></a>\n" +
	                    "<a href=\"#\" class=\"btn btn-default btn-lg open_camera_pc\"   ><i class=\"iconfont icon-paishe\" style=\"font-size:2rem\"></i>&nbsp;打开高拍仪</a>\n" +
	                    "<a href=\"#\" class=\"btn btn-default btn-lg \"></a>\n" +
	                    "</div>");
                }
            }


            /**
             * 拍照-事件委托方式
             */
            $("body").on('click', ".confirm_photo", function () {
                //设置消息样式
                msgTool.options = {
                    "positionClass": "toast-bottom-right",
                    "timeOut": "5000"
                };
                send_command(
                    "takePhoto",
                    "nothing",
                    function (receivedData) {
                        var photoBean = JSON.parse(receivedData);
                        if (photoBean.status === 100) {
                            var result = updateBase64('data:image/jpeg;base64,' + photoBean.imgStr);
                            if (result.status) {
                                //添加上传图片
                                $("#imagesUploadShow").append("<div class=\"col-xs-12 col-sm-4 mb15\">\n" +
                                    "<div class=\"thumbnail images-box\"><input type=\"hidden\" name=\"companyImagesList\" value=\"" + result.url + "\">\n" +
                                    "<img src=\"" + result.domain + result.url + "\">\n" +
                                    "</div>\n" +
                                    "<div class=\"caption\">\n" +
                                    "<div class=\"btn btn-block btn-danger deletetCover\" onclick=\"$(this).parent().parent().remove()\"><i class=\"iconfont icon-remove\"></i>&nbsp;删除</div>\n" +
                                    "</div>\n" +
                                    "</div>");
                                msgTool["success"]("添加资料图片成功", "提示");
                            } else {
                                msgTool["error"](result.message, "提示");
                            }


                        } else if (photoBean.status === 300) {
                            msgTool["error"]('模块未开启', "提示");
                        } else if (photoBean.status === 200) {
                            msgTool["error"]('拍照关闭失败：' + photoBean.msg, "提示");
                        }
                    }
                );
            });

            
            /**
             * 打开pc高拍仪
             */
            $("body").on('click', ".open_camera_pc", function () {

            	// 调用show方法
                BootstrapDialog.show({
                    type: BootstrapDialog.TYPE_DEFAULT,
                	closable: true,	//关闭箭头启动
                    closeByBackdrop: false,	//点击空白不消失
                    closeByKeyboard: true,//ESC取消禁用
                    title : '高拍仪 ',
                    message : '<object id="view"  type="application/x-eloamplugin" width="560" height="400"   name="view"   ></object>',
                    buttons: [{
                        label: '拍照',
                        cssClass: 'btn-primary',
                        icon: 'fa fa-times',
                        action: function (dialog) {
                        	Scan("#imagesUploadShow","companyImagesList");
                        }
                    }, {
                        label: '关闭',
                        cssClass: 'btn-white cancel',
                        icon: 'fa fa-check',
                        action: function (dialog) {
                        	 dialog.close();  //返回验证结果
                        }
                    }],
                    onshown: function () {
                       Load();
                    },
                    onhide : function () {
                      	CloseVideo();           
                    }
                });
		         
            });
            

            /**
             * 提交下一步
             */
            $("#doSubmit").on('click', function () {

                var valid = $("#companyIndexForm").valid();

                if (valid) {
                    $.ajax({
                        url: "/companyApply/save",
                        type: 'POST',
                        data: $("#companyIndexForm").serialize(),
                        dataType: "JSON",
                        beforeSend: function () {
                            //触发ajax请求开始时执行
                            $("#doSubmit").text('提交中...');
                            $("#doSubmit").attr('disabled', 'disabled');
                        },
                        success: function (data) {
                            if (data.success) {
                                window.location.href = "/companyApplyMember/shareholder/" + data.model.id;
                            } else {
                                $("#messageCode").text(data.msg);
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            $("#messageCode").text("登录注册，请刷新页面后重试！");
                        },
                        complete: function () {
                            $("#doSubmit").text("下一步");
                            $("#doSubmit").removeAttr('disabled');
                        }
                    });
                }
            });
        },
        /**
         * 子女
         */

        houseIndex: function (lawsuitId) {

            /**
             * 页面加载后，初始化上传控件
             */
        	var count = $("form[name='relativesForm']").length;
        	for (var i = 1; i <= count; i++) {
        	    new uploadInit("relatives_" + i);
        	}

            /**
             * 执行上传初始化
             * @constructor
             */
            function uploadInit(uniqueNode) {
                if (window.isAIO !== undefined && window.isAIO) {
                    $(".upload-tips").html("打开高拍仪，并放置当前股东证件，点击确认添加按钮即可。");
                    $("#camera_tool_open").html("<div class=\"form-group\">" +
                        "<div class=\"col-sm-2 camera_tool_fixed\">" +
                        "<div class=\"alert alert-warning  btn-group btn-group-vertical\">\n" +
                        "<button type='button' class=\"btn btn-default btn-lg btn-block open_camera\" data-open-type=\"2\"><i class=\"iconfont icon-paishe\" style=\"font-size:2rem\"></i>&nbsp;打开高拍仪</button>" +
                        "<button type='button' class=\"btn btn-default btn-lg btn-block close_camera\"><i class=\"iconfont icon-guanbi\" style=\"font-size:2rem\"></i>&nbsp;关闭高拍仪</button>\n" +
                        "</div></div></div>");

                    $("input[name='cardFrontPicture']").next(".input-group-btn").html("<button type=\"button\" class=\"btn btn-success btn-outline confirm_photo\">确认添加正面照</button>");

                    $("input[name='cardBackPicture']").next(".input-group-btn").html("<button type=\"button\" class=\"btn btn-success btn-outline confirm_photo\">确认添加背面照</button>");

                } else {
                    //房产证
                    uploader(uniqueNode, ".cardFrontUploader", true, 0, false, "正面照", uniqueNode + " .front-error-message", uniqueNode + " [name='card']", uniqueNode + " .cardFrontPictureShow");
                
                    if (checkDevice()) {
                    $("legend").each(function(index,ele){
                    	index++;
                        var Html="第" + index + "个房产信息："+
                        "<button onclick=\"readIDcard("+index+")\" class=\"btn btn-info mb5\">读取身份证</button>&nbsp; &nbsp;"+
                  		"<button onclick=\"$(this).parents('form').remove()\" class=\"btn btn-danger mb5\">删除</button>" ;
                    	$(ele).html(Html);
                    })
                    }
                    
                }
            }


            //添加子女
            $("body").on('click', '#addHouse', function () {
                var formNode = $("body").find("form[name='houseForm']");
                var formId = formNode.length + 1;
                var formKey = "house_" + formId;
                var investmentModeKey = "investmentMode_" + formId + "_";
                var IDCardHtml="";
                if (checkDevice()) {
                	IDCardHtml="<button onclick=\"readIDcard("+formId+")\" class=\"btn btn-info mb5\">读取身份证</button>&nbsp; &nbsp; ";
                }
                $("#moreHouse").append("<form id=\"" + formKey + "\" class=\"form-horizontal\" name=\"houseForm\" method=\"post\" role=\"form\"><input class=\"form-control\" name=\"lawsuitId\" type=\"hidden\" value=\"" + lawsuitId + "\"><legend>第" + formId + "个房产信息：" +
                		""+IDCardHtml+""+
                		"<button onclick=\"$(this).parents('form').remove()\" class=\"btn btn-danger mb5\">删除</button>" +
                		"</legend> <div class=\"form-group\"><label class=\"col-sm-2 control-label\"><i class=\"text-danger\">*</i>房屋地址：</label><div class=\"col-sm-5\"><input name=\"address\" class=\"form-control\" placeholder=\"请输入房屋地址\" type=\"text\" required aria-required=\"true\" minlength=\"2\" maxlength=\"50\"></div></div>  <div class=\"form-group\"><label class=\"col-sm-2 control-label\"><i class=\"text-danger\">*</i>房屋面积(㎡)：</label><div class=\"col-sm-5\"><input name=\"area\" class=\"form-control\" placeholder=\"请输入房屋面积\" type=\"number\" required aria-required=\"true\" minlength=\"2\" maxlength=\"50\"></div></div> <div class=\"form-group\"><label class=\"col-sm-2 control-label\"><i class=\"text-danger\">*</i>房屋性质：</label><div class=\"col-sm-5\"><select class=\"form-control\" name=\"nature\" required aria-required=\"true\"><option value=\"商品房\">商品房</option><option value=\"公房\">公房</option><option value=\"经济适用房\">经济适用房</option></select></div></div> <div class=\"form-group\"><label class=\"col-sm-2 control-label\"><i class=\"text-danger\">*</i>房产证号：</label><div class=\"col-sm-5\"><input name=\"cardNumber\" class=\"form-control\" placeholder=\"请输入房产证号\" type=\"text\" required aria-required=\"true\" maxlength=\"18\"></div></div>   <div id=\"camera_tool_open\"></div> <div class=\"form-group\"><label class=\"col-sm-2 control-label\"><i class=\"text-danger\">*</i>房产证照片：</label><div class=\"col-sm-5\"><b class='text-danger upload-tips'></b><div class=\"input-group\"><input name=\"card\" class=\"form-control mb10\" type=\"text\" readonly placeholder=\"请选择...\" required> <span class=\"input-group-btn\"><input name=\"files\" class=\"form-control cardFrontUploader\" type=\"file\"></span></div><div class=\"cardFrontPictureShow center-block row\"></div><div class=\"front-error-message\"></div></div></div> <hr></form>");
                new uploadInit("#" + formKey);

            });




            /**
             * 拍照-事件委托方式
             */
            $("body").on('click', ".confirm_photo", function () {
                var button = $(this);
                //设置消息样式
                msgTool.options = {
                    "positionClass": "toast-bottom-right",
                    "timeOut": "5000"
                };
                send_command(
                    "takePhoto",
                    "nothing",
                    function (receivedData) {
                        var photoBean = JSON.parse(receivedData);
                        if (photoBean.status === 100) {
                            var result = updateBase64('data:image/jpeg;base64,' + photoBean.imgStr);
                            if (result.status) {
                                //添加url隐藏域
                                $(button).parent().prev('input').val(result.url);
                                //添加预览图
                                $(button).parents(".input-group").next("div").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><img src=\"" + result.domain + result.url + "\" style=\"width: 100%\"></div></div>");

                                msgTool["success"](button.text() + "成功", "提示");
                            } else {
                                msgTool["error"](result.message, "提示");
                            }
                        } else if (photoBean.status === 300) {
                            msgTool["error"]('模块未开启', "提示");
                        } else if (photoBean.status === 200) {
                            msgTool["error"]('拍照关闭失败：' + photoBean.msg, "提示");
                        }
                    }
                );
            });

            /**
             * 提交添加
             */
            $("#doSubmit").on('click', function () {
                    if (window.isAIO !== undefined && window.isAIO) {
                        closeCamera();
                    }
                    var dataFormStatus = false;
                    var form = $("form[name='houseForm']");
                    $.each(form, function () {
                        // dataFormStatus = $(this).valid();
                        dataFormStatus = $(this).validate().form();
                    });


                    var houseDOList = [];
                    if (dataFormStatus) {
                        var length = form.length;
                        //定义要传递的数组
                        for (var i = 1; i <= length; i++) {
                            var formJson = getFormJson($("#house_" + i));
                            houseDOList.push(formJson);
                        }
                        $.ajax({
                            url: "/court/house/save/"+lawsuitId,
                            type: 'POST',
                            data: JSON.stringify(houseDOList),
                            dataType: "JSON",
                            contentType: 'application/json;charset=utf-8',
                            beforeSend: function () {
                                //触发ajax请求开始时执行
                                $("#doSubmit").text('提交中...');
                                $("#doSubmit").attr('disabled', 'disabled');
                            },
                            success: function (data) {
                                if (data.success) {
                                    window.location.href = "/court/asset/" + lawsuitId;
                                    // alert("成功");
                                } else {
                                    $("#messageCode").text(data.msg);
                                }
                            },
                            error: function (error) {
                                $("#messageCode").text("保存失败，请刷新当前页面后重试！");
                            },
                            complete: function () {
                                $("#doSubmit").text("下一步");
                                $("#doSubmit").removeAttr('disabled');
                            }
                        });
                    }else {

                        var formLength = $("body").find("form[name='houseForm']").length;
                        if (formLength > 0) {
                            return false;
                        }

                        $.ajax({
                            url: "/court/house/save/"+lawsuitId,
                            type: 'POST',
                            data: JSON.stringify(houseDOList),
                            dataType: "JSON",
                            contentType: 'application/json;charset=utf-8',
                            beforeSend: function () {
                                //触发ajax请求开始时执行
                                $("#doSubmit").text('提交中...');
                                $("#doSubmit").attr('disabled', 'disabled');
                            },
                            success: function (data) {
                                console.log(data);
                                if (data.success) {
                                    window.location.href = "/court/asset/" + lawsuitId;
                                    // alert("没有");
                                } else {
                                    $("#messageCode").text(data.msg);
                                }
                            },
                            error: function (error) {
                                $("#messageCode").text("请刷新当前页面后重试！");
                            },
                            complete: function () {
                                $("#doSubmit").text("下一步");
                                $("#doSubmit").removeAttr('disabled');
                            }
                        });
                    }
                }
            );
        },
        /**
         * 法人、董事、经理、监事、财务负责人、联络人、经办人
         */
        member: function (uploaderFilesDomain, nextPage) {

            if (window.isAIO !== undefined && window.isAIO) {

                $(".upload-tips").html("打开高拍仪，并放置当前成员证件，点击确认添加按钮即可。");
                $("#camera_tool_open").html("<div class=\"form-group\">" +
                    "<div class=\"col-sm-2 camera_tool_fixed\">" +
                    "<div class=\"alert alert-warning  btn-group btn-group-vertical\">\n" +
                    "<button type='button'  class=\"btn btn-default btn-lg btn-block open_camera\" data-open-type=\"2\"><i class=\"iconfont icon-paishe\" style=\"font-size:2rem\"></i>&nbsp;打开高拍仪</button>" +
                    "<button type='button'  class=\"btn btn-default btn-lg btn-block close_camera\"><i class=\"iconfont icon-guanbi\" style=\"font-size:2rem\"></i>&nbsp;关闭高拍仪</button>\n" +
                    "</div></div></div>");

                $("#cardFrontPicture").next(".input-group-btn").html("<button type=\"button\" class=\"btn btn-success btn-outline confirm_photo\">确认添加正面照</button>");

                $("#cardBackPicture").next(".input-group-btn").html("<button type=\"button\" class=\"btn btn-success btn-outline confirm_photo\">确认添加背面照</button>");

            } else {
                //证件正面照
                uploader(null, "#cardFrontUploader", true, 0, false, "正面照", "#front-error-message", "#cardFrontPicture", "#cardFrontPictureShow");
                //证件反面照
                uploader(null, "#cardBackUploader", true, 0, false, "反面照", "#back-error-message", "#cardBackPicture", "#cardBackPictureShow");
                if (checkDevice()) {
                	$("#readIDCard").html("<a  class=\"btn btn-info mb5  open_idcard_pc\">读取身份证</a>");
                }
            
            }


            // //股东下拉
            // $.baseUtils.select({
            //     cssName: "#selectShareholder",
            //     dataName: "name",
            //     url: "/companyApplyMember/shareholder/list/" + $("#applyId").val()
            // });


            /**
             * 选中股东后，充填输入框
             */
            $('#selectShareholder').on('select2:select', function (event) {
                var data = event.params.data;
                $("#id").val(data.id);
                $("#name").val(data.name);
                $("#cardNumber").val(data.cardNumber);
                $("#phone").val(data.phone);
                $("#email").val(data.email);
                $("#cardType").val(data.cardType);
                $("#cardFrontPicture").val(data.cardFrontPicture);
                $("#cardFrontPictureShow").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><img src=\"" + uploaderFilesDomain + data.cardFrontPicture + "\"></div></div>");
                $("#cardBackPicture").val(data.cardBackPicture);
                $("#cardBackPictureShow").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><img src=\"" + uploaderFilesDomain + data.cardBackPicture + "\"></div></div>");
                //执行cardType切换
                memberCardTypeSwitchExecute($("#cardType"), $(event.target).parents("form"));
            });


            /**
             * 拍照-事件委托方式
             */
            $("body").on('click', ".confirm_photo", function () {
                var button = $(this);
                //设置消息样式
                msgTool.options = {
                    "positionClass": "toast-bottom-right",
                    "timeOut": "5000"
                };
                send_command(
                    "takePhoto",
                    "nothing",
                    function (receivedData) {
                        var photoBean = JSON.parse(receivedData);
                        if (photoBean.status === 100) {
                            var result = updateBase64('data:image/jpeg;base64,' + photoBean.imgStr);
                            if (result.status) {
                                //添加url隐藏域
                                $(button).parent().prev('input').val(result.url);
                                //添加预览图
                                $(button).parents(".input-group").next("div").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><img src=\"" + result.domain + result.url + "\" style=\"width: 100%\"></div></div>");

                                msgTool["success"](button.text() + "成功", "提示");
                            } else {
                                msgTool["error"](result.message, "提示");
                            }
                        } else if (photoBean.status === 300) {
                            msgTool["error"]('模块未开启', "提示");
                        } else if (photoBean.status === 200) {
                            msgTool["error"]('拍照关闭失败：' + photoBean.msg, "提示");
                        }
                    }
                );
            });


            

            /**
             * 高拍仪身份证读取
             * */

            $("body").on('click', ".open_idcard_pc", function () { 
                var obj = ReadIDCard();
            	$("#name").val(obj.name);
            	$("#cardType").val(1);
            	$("#cardNumber").val(obj.idcard);
            		var result = updateBase64('data:image/jpeg;base64,' + obj.IDcard_frontImg_base64);
            		if (result.status) {
            			$("#cardFrontPicture").val(result.url);
            			$("#cardFrontPictureShow").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><a href=\"" + result.domain + result.url + "\" target=\"_blank\"><img src=\"" + result.domain + result.url + "\"  style=\"width: 100%\"></a></div></div>");
            		} else {
            			obj.message=result.message;
            		}	
            		
            	var result = updateBase64('data:image/jpeg;base64,' + obj.IDcard_backImg_base64);
            	if (result.status) {
            		$("#cardBackPictureShow").val(result.url);
            		$("#cardBackPictureShow").html("<div class=\"mb15 mt15\"><div class=\"thumbnail images-box\"><a href=\"" + result.domain + result.url + "\" target=\"_blank\"><img src=\"" + result.domain + result.url + "\"   style=\"width: 100%\"></a></div></div>");
            	} else {
            		obj.message=result.message;
            	}	
                
                if (obj.message != null) {
                    msgTool["error"](obj.message, '提示');
                } else {
                    msgTool["success"]('身份证读取成功！', '提示');
                }
            });


            
            /**
             * 提交添加
             */
            $("#doSubmit").on('click', function () {

                    var dataFormStatus = $("#memeberForm").valid();
                    if (dataFormStatus) {
                        $.ajax({
                            url: "save.json",
                            type: 'POST',
                            data: $("#memeberForm").serialize(),
                            dataType: "JSON",
                            beforeSend: function () {
                                //触发ajax请求开始时执行
                                $("#doSubmit").text('提交中...');
                                $("#doSubmit").attr('disabled', 'disabled');
                            },
                            success: function (data) {
                                if (data.success) {
                                    window.location.href = nextPage;
                                } else {
                                    $("#messageCode").text(data.msg);
                                }
                            },
                            error: function (error) {
                                $("#messageCode").text("保存失败，请刷新当前页面后重试！");
                            },
                            complete: function () {
                                $("#doSubmit").text("下一步");
                                $("#doSubmit").removeAttr('disabled');
                            }
                        });
                    }
                }
            );

        },
        /**
         * 申请成功
         */
        success: function () {
            console.log("申请成功.js。。。。。");
        }
    };
});
